<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>批量设置排班</title>
    <link rel="stylesheet" type="text/css" href="../lib/laydate.css"/>
    <link rel="stylesheet" type="text/css" href="../lib/pagination/style/pagination.css"/>
    <link rel="stylesheet" type="text/css" href="../css/base.css"/>
    <script type="text/javascript" src="../js/common/language.js" ></script>
    <script type="text/javascript" src="../js/news/jquery-1.9.1.js"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/news/page.js"></script>
    <script src="../lib/laydate.js"></script>
    <script src="../js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="/js/ajaxupload.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jquery.form.min.js"></script>
    <script src="../lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../lib/layer/layer.js?20201106"></script>
    <style>
        a{
            text-decoration: none;
            color: #207bd6;
        }

        .buttonDiv>div{
            float: left;
            margin: 20px 10px;
        }
        .fileDone select{
            width: 160px;
            height:28px;
        }
        #tr_td tr:nth-child(odd){
            background-color: #fff;
        }
        input{
            float: none;
            width: 200px;
            height: 30px;
        }
        select{
            width: 200px;
            height: 30px;
        }
        textarea{
            width: 260px;
            height: 50px;
            vertical-align: middle;
        }
        a{
            text-decoration: none;
            color: #207bd6;
        }
        .newTbale tr td{
            border-right: #ccc 1px solid;
            padding: 5px;
        }
        .main{
            width: 40%;
            margin: 0 auto;
        }
        .main table{
            width: 100%;
        }
        .main table tr td{
            text-align: left;
            padding: 8px;
            border-right: #ccc 1px solid;
        }
        .saveBtn{
            width: 40px;
            height: 28px;
            background: #2b7fe0;
            border-radius: 4px;
            cursor: pointer;
            text-align: center;
            color: #ffffff;
            line-height: 28px;
            margin: 0 auto;
            float: left;
        }
    </style>
</head>

<body>
<div class="bx">
    <div class="navigation  clearfix juMange" id="maSet" style="display: block;">
        <div class="left" style="margin-left: 30px">
            <img src="/img/commonTheme/${sessionScope.InterfaceModel}/icon_manageFile.png">
            <div class="news">批量设置排班</div>
        </div>
        <div style="clear: both;"></div>
        <div class="wrap" style="margin-left: 0;padding: 0 20px;">
            <div class="main">
                <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse">
                    <tr>
                        <td>起始日期：</td>
                        <td>
                            <input id="dateStart" type="text" name="datestart" value="" onclick="laydates()">
                        </td>
                    </tr>
                    <tr>
                        <td>结束日期：</td>
                        <td>
                            <input id="dateEnd" type="text" name="dateend" value="" onclick="laydatex()">
                        </td>
                    </tr>
                    <tr>
                        <td>选择班次：</td>
                        <td>
                            <select name="machingBrand" id="machingBrand">

                            </select>
                        </td>
                    </tr>

                    <tr>
                        <td>设置范围（部门）：</td>
                        <td>
                            <textarea name="" id="s1" disabled></textarea>
                            <a href="javascript:;" style="margin: 0 10px;" id="a1" class="a1">添加</a>
                            <a href="javascript:;"  class="clear" style="color: red">清空</a>
                        </td>
                    </tr>
                    <tr>
                        <td>设置范围（角色）：</td>
                        <td>
                            <textarea name="" id="s2" disabled></textarea>
                            <a href="javascript:;" style="margin: 0 10px;" id="a2" class="a2">添加</a>
                            <a href="javascript:;"  class="clear" style="color: red">清空</a>
                        </td>
                    </tr>
                    <tr>
                        <td>设置范围（人员）：</td>
                        <td>
                            <textarea name="" id="s3" disabled></textarea>
                            <a href="javascript:;" style="margin: 0 10px;" id="a3" class="a3">添加</a>
                            <a href="javascript:;"  class="clear" style="color: red">清空</a>
                        </td>
                    </tr>

                    <tr>
                        <td>备注：</td>
                        <td>
                            <p style="color: #ff0000;">1.排班信息会覆盖原有数据,请谨慎操作</p>
                            <p style="color: #ff0000;">2.批量调班优先级大于排班设置中公休日以及免签节假日,请谨慎操作</p>
                            <p style="color: #ff0000;">3.考勤统计按天计算排班，未给用户排班的天次按休息处理</p>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">

                            <div style="width: 130px;margin: 0 auto">
                                <div class="saveBtn" id="saveBtn" style="margin-right: 20px">确定</div>
                                <div class="saveBtn" id="backs">返回</div>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
//        返回

        $('#backs').click(function () {
            parent.window.location.href='/attendanceWay/attindex'
        })
//        保存
        $('#saveBtn').click(function () {
            if($('#dateStart').val()==''){
                $.layerMsg({content:'请填写起始日期！',icon:1})
                return false;
            }
            if($('#dateEnd').val()==''){
                $.layerMsg({content:'请填写结束日期！',icon:1})
                return false;
            }
            var setId1=$("#machingBrand").val();
            if(setId1==undefined||setId1==""){
                setId1=null;
            }
            var data={
                dateStart:$("#dateStart").val(),
                dateEnd:$("#dateEnd").val(),
                setId:setId1,
                deptId:$("#s1").attr("deptid"),
                privId:$("#s2").attr("userpriv"),
                userId:$("#s3").attr("user_id")
            }
            if(data.deptId==undefined&&data.privId==undefined&&data.userId==undefined){
                $.layerMsg({content:'请选择人员！',icon:1})
                return false;
            }
            layer.load(0);
            $.ajax({
                type:'post',
                url:'/attendSchedule/saveUserDuty',
                dataType:'json',
                data:data,
                success:function(res){
                    layer.closeAll();
                    if(res.flag){
                        layer.msg('保存成功！', { icon:6},function () {
                            window.location.reload();
                        });
                    }else{
                        $.layerMsg({content:'保存失败！',icon:2})
                    }
                }
            })
        });


        //选择部门
        $('#a1').click(function(){
            dept_id="s1";
            $.popWindow("../../common/selectDept");
        })

        //选择角色
        $("#a2").on("click", function () {
            priv_id = 's2';
            $.popWindow("../common/selectPriv");
        });

        //选择人员
        $('.a3').click(function(){
            user_id="s3";
            $.popWindow("../../common/selectUser");
        });

    })
    window.onload=function() {
        $.ajax({
            type:'get',
            url:'/attendSchedule/getAttendSet',
            dataType:'json',
            success:function (res) {
                if(res.flag){
                    var obj=res.obj;
                    for(var i=0;i<obj.length;i++){
                        var attendSet=obj[i];
                        var sid=attendSet.sid;
                        if(sid=="undefined"||sid==undefined){
                            sid=0;
                        }
                        var title=attendSet.title;
                        var option="<option value="+"'"+sid+"'"+">"+title+"</option>";
                        $("#machingBrand").append(option);
                    }
                }
            }
        })
    }
    function laydates() {
        laydate({
            elem: '#dateStart',
            format: 'YYYY-MM-DD',
//                        min: laydate.now(), //设定最小日期为当前日期*/
//        max: '2099-06-16 23:59:59', //最大日期*/
            istime: true,
            istoday: false
//        choose: function(datas){
//            end.min = datas; //开始日选好后，重置结束日的最小日期
//            end.start = datas; //将结束日的初始值设定为开始日
//        }
        })
    }

    function laydatex() {
        laydate({
            elem: '#dateEnd',
            format: 'YYYY-MM-DD',
//                        min: laydate.now(), //设定最小日期为当前日期*/
//        max: '2099-06-16 23:59:59', //最大日期*/
            istime: true,
            istoday: false
//        choose: function(datas){
//            end.min = datas; //开始日选好后，重置结束日的最小日期
//            end.start = datas; //将结束日的初始值设定为开始日
//        }
        })
    }
    //清空
    $(".clear").click(function () {
        var parentClear=$(this).parent();
        alert(parentClear);
        var textarea=parentClear.children("textarea");
        textarea.val("");
        textarea.attr("deptid","");
        textarea.attr("userpriv","");
        textarea.attr("user_id","")

    })

</script>
</body>
</html>
